var User = require('../models/User');
var Activity = require('../models/Activity');
var ActivityUser = require('../models/ActivityUser');

exports.myHelpers = function(req,res){
	var event_id = req.query.event_id;
	var open_id = req.query.open_id;

	User.findOne({openid:open_id},function(err,user){
		if(err){
			res.json({code:0})
		}else{
			if(user){
				Activity.findOne({event_id:event_id,user_id:user._id},function(err,activity){
					if(err){
						res.json({code:0})
					}else{
						if(activity){
							ActivityUser.find({activity_id:activity._id})
										.populate('user_id')
										.exec(function(err,records){
											if(err){
												res.json({code:0})
											}else{
												res.json({code:1,data:records})
											}
										})
						}else{
							res.json({code:0})
						}
					}
				})
			}else{
				res.json({code:0})
			}
		}
	})
}
